﻿using System.Collections.Generic;

namespace NpPuzzleGame
{
	public class Level
	{
		private List<Block> allBlocks = new List<Block>()
		{
			new Block(30, 30, 60, 60)
		};

		public Level() { }

		public List<Block> AllBlocks { get { return this.allBlocks; } }

		public void TryUpdatePosition(Sprite sprite)
		{
			int newX = sprite.X + sprite.DX;
			int newY = sprite.Y + sprite.DY;

			if (!this.CanOccupy(newX, newY, sprite.Width, sprite.Height))
			{
				return;
			}

			sprite.X = newX;
			sprite.Y = newY;
		}

		public bool CanOccupy(int left, int top, int width, int height)
		{
			int right = left + width;
			int bottom = top + height;
			foreach (Block block in this.allBlocks)
			{
				if (block.IsCollision(left, top, right, bottom))
				{
					return false;
				}
			}
			return true;
		}
	}
}